added Feb 2001 SDK
[windows-sources.git] / shared source / wpf / src / host / dll / disablexappdocuments.cxx
blob66f2bbc9db486dcfe4923fadd0a1d333493b43ac
1 //+-----------------------------------------------------------------------
2 //
3 // Copyright (c) Microsoft Corporation. All rights reserved.
4 //
5 // Description:
6 // This file has all the code that detects whether the registry keys
7 // to disable xps documents and xapps are set.
8 // History:
9 // 2005/06/09 - akaza Created the file
10 // 2007/09/20 - [....]
11 // Ported Windows->DevDiv. See SourcesHistory.txt.
13 //------------------------------------------------------------------------
14 #include "Precompiled.hxx"
15 #include "DisableXappDocuments.hxx"
16 #include "UrlMonInterop.hxx"
17 #include "OleDocument.hxx"
18 #include "HostSupport.h"
19 #include "..\inc\registry.hxx"
21 // EXPLICIT definition because IE versions lesser than 7 will not have this value and will probabaly
22 // not recognize it.
24 #define URLMON_OPTION_FOR_BROWSERAPPSDOCUMENTS 0x10000010
25 #define URLACTION_WEB_BROWSER_APPLICATIONS_INTERNAL 0x00002400
26 #define URLACTION_XPS_DOCUMENTS_INTERNAL 0x00002401
27 #define URLACTION_LOOSE_XAML_INTERNAL 0x00002402
29 // generic function that checks presence or absence of a reg key in HKLM
30 // returns true if the key is present and its value is 1 , false otherwise
31 // pRegkeyLocationToCheck: The key in HKLM to open
32 // pRegKeyToExtract: The specific key to look for
33 BOOL IsDisableKeySet(LPCTSTR pRegkeyLocationToCheck, LPCTSTR pRegKeyToExtract)
35 LONG lRet = ERROR_SUCCESS;
36 HKEY hKey = NULL;
37 DWORD dwUnrestricted = 0;
38 DWORD dwSize = sizeof(dwUnrestricted);
41 // throw exception in case pointer is null
42 Assert((pRegkeyLocationToCheck!=NULL) &&
43 (pRegKeyToExtract!=NULL));
45 // If it doesn't exist or if key exists and is 0 then return false
46 // if it exists and is set to 1, then return true
47 lRet = RegOpenKeyEx(HKEY_LOCAL_MACHINE,
48 pRegkeyLocationToCheck,
50 KEY_QUERY_VALUE,
51 &hKey);
53 if (ERROR_SUCCESS == lRet)
55 lRet = RegQueryValueEx(hKey,
56 pRegKeyToExtract,
57 NULL,
58 NULL,
59 (LPBYTE)&dwUnrestricted,
60 &dwSize);
61 RegCloseKey(hKey);
63 return (ERROR_SUCCESS == lRet && dwUnrestricted == 1);
68 BOOL IsMimeTypeDisabled(__in_ecount(INTERNET_MAX_URL_LENGTH+1) LPOLESTR pUrl, __in_ecount(1) COleDocument* pOleDoc)
70 MimeType mimeType = pOleDoc->GetCurrentMime();
71 DWORD dwAction = URLACTION_WEB_BROWSER_APPLICATIONS_INTERNAL;
73 // Get the mime type
74 switch(mimeType)
76 case MimeType_Application:
77 if (IsDisableKeySet(RegKey_WPF_Features, RegValue_XBAPDisallow))
78 return TRUE;
79 break;
81 case MimeType_Xps:
82 if (IsDisableKeySet(RegKey_WPF_Features, RegValue_XPSDocumentsDisallow))
83 return TRUE;
84 dwAction = URLACTION_XPS_DOCUMENTS_INTERNAL;
85 break;
87 case MimeType_Markup:
88 if (IsDisableKeySet(RegKey_WPF_Features, RegValue_LooseXamlDisallow))
89 return TRUE;
90 dwAction = URLACTION_LOOSE_XAML_INTERNAL;
91 break;
94 // The fact that the previous call returned false could mean one of two things
95 // either the key was available and value was set to zero (which should not happen)
96 // or the key does not exist.
97 // The key being set to zero could mean that we decided to disable this reg key or user did it
98 // to allow xapps to work. We should in the most case not encounter this.
99 // If the key was not present it could mean one of two things , either it was never there or
100 // we are on IE7. On IE 7 we want to run processUrlAction The following call does that for us
102 return !ProcessURLActionOnIE7(dwAction,pUrl,pOleDoc);
107 // action indicates the mimetype we are dealing with
108 BOOL ProcessURLActionOnIE7(DWORD action, __in_ecount(INTERNET_MAX_URL_LENGTH+1) LPOLESTR pUrl, __in_ecount(1) COleDocument* pOleDoc)
110 HRESULT hr = S_OK;
111 DWORD dwResult = 0;
112 LPBYTE dummyPtr = new BYTE[sizeof(DWORD)];
114 Assert(pUrl != NULL);
116 Assert(pOleDoc != NULL);
118 // The following code calls into UrlMkGetSessionOption with the flag for URLMON_OPTION_USE_BROWSERAPPSDOCUMENTS
119 // if the return is E_INVALIDARGS then we are on a version of IE lesser than 7 else we get NOERROR.
120 // In the case where we get NOERROR we call ProcessURLAction with the appropriate flag for XAPPs or XPS
121 // depending on the value of the parameter passed in.
123 hr = UrlMkGetSessionOption(URLMON_OPTION_FOR_BROWSERAPPSDOCUMENTS, dummyPtr, sizeof(DWORD), &dwResult, 0);
124 if (dummyPtr)
126 delete [] dummyPtr;
128 // this is the case where we are on a lower version of IE than version 7
130 if (E_INVALIDARG == hr)
132 return TRUE;
135 // in this case we call ProcessURLAction depending on whether it is an application or a document
137 BOOL fAllow = FALSE;
138 if (NOERROR == hr)
140 // at this time COM is already initialized so I do not
141 // call CoInitializeEx
142 // we do not really care about the return hr for this call since it returns
143 // either S_OK for allow or S_FALSE for ~S_ALLOW or E_OUTOFMEMORY
145 hr = UrlmonInterop::ProcessUrlActionWrapper(action, pUrl, pOleDoc,fAllow);
147 return fAllow;